package com.tanhua.app.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.tanhua.app.Service.SoulService;
import com.tanhua.model.pojo.Answers;
import com.tanhua.model.vo.SoulReportVo;
import com.tanhua.model.vo.SoulVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class SoulController {
    @Autowired
    private SoulService soulService;

//    测灵魂-问卷列表（学生实战)
//    GET   /testSoul
    @GetMapping
    public ResponseEntity testSoul(){
        List<SoulVo> vo = soulService.getTest();
        return ResponseEntity.ok(vo);
    }

//    测灵魂-提交问卷（学生实战）
//    POST  /testSoul
    @PostMapping
    public ResponseEntity soulAnswer(@RequestBody Map<String,List<Answers>> map){
//        System.out.println(arr);
//        JSONArray objects = JSONUtil.parseArray(arr);
//        List<Answers> answers = JSONUtil.toList(objects, Answers.class);
//        System.out.println(answers);
        List<Answers> answers = map.get("answers");
        String reportId = soulService.getAnswer(answers);
        return ResponseEntity.ok(reportId);
    }

//    测灵魂-查看结果（学生实战）
//    GET   /testSoul/report/:id
    @GetMapping("/report/{id}")
    public ResponseEntity report(@PathVariable("id") String id){
        SoulReportVo vo = soulService.findReport(id);
        return ResponseEntity.ok(vo);
    }
}
